home *** CD-ROM | disk | FTP | other *** search
- Path: cityscape.co.uk!usenet
- From: es07@cityscape.co.uk (David Ascroft)
- Newsgroups: comp.lang.c++
- Subject: Re: new with multidimensional arrays
- Date: 11 Apr 1996 00:01:12 GMT
- Organization: IP-GOLD User
- Message-ID: <4khi48$m2d@news.cityscape.co.uk>
- References: <3169B9C3.2A10@MIT.EDU>
- NNTP-Posting-Host: cises07.demon.co.uk
- X-Newsreader: WinVN 0.92.6+
-
- In article <3169B9C3.2A10@MIT.EDU>, Darrel K Robertson <dkr1@MIT.EDU> says:
- >
- >Hi, I wonder if anyone can help me. I want to use "new" to create a
- >multidimensional array, but don't know how. So far I have:
- >complex *grid;
- >scanf("%d %d", &nc, &nr);
- >grid = new complex[nc][nr];
- >
- >Unfortunately this won't work. Any info would be much appreciated.
- >Darrel.
-
- Try this (with nc and nr being the size of the two-dimensional array):
-
- // First coordinate.
- complex **grid = new complex *[nc];
-
- // For each first coordinate, allocate the corresponding second.
- for (int x = 0; x < nc; x++)
- grid[x] = new complex[nr];
-
- Dave
-